﻿using HandyControl.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace HMI.View
{
    /// <summary>
    /// WinMenu.xaml 的交互逻辑
    /// </summary>
    public partial class WinMenu : UserControl
    {
        public WinMenu()
        {
            InitializeComponent();
            InitializeItems();
        }
        public Action<ProjectModel> ClickItem { get; set; }
        public void InitializeItems()
        {
            foreach (WinItem winItem in skp.Children)
            {
                winItem.ClickItem = new Action<ProjectModel>((ProjectModel projectModelx) => {
                    foreach (WinItem item in skp.Children)
                    {
                        if (projectModelx.Index == item.Index)
                        {
                            item.Selected = true;
                        }
                        else
                        {
                            item.Selected = false;
                        }
                    }
                    if (ClickItem != null)
                        ClickItem(projectModelx);
                });
            }
        }
        public Action<bool> HideAction { get; set; }
        public bool HideMenu
        {
            set
            {
                if (!value)
                {
                    datacon.ColumnDefinitions[0].Width = new GridLength(1, GridUnitType.Star);
                    datacon.ColumnDefinitions[1].Width = new GridLength(0);
                    sidebtn.Visibility = Visibility.Hidden;
                }
                else
                {
                    datacon.ColumnDefinitions[0].Width = new GridLength(0);
                    datacon.ColumnDefinitions[1].Width = new GridLength(30);
                    sidebtn.Visibility = Visibility.Visible;
                }
                if (HideAction != null)
                    HideAction(value);
            }
        }
        public void SelectMenu(int index)
        {
            foreach (WinItem item in skp.Children)
            {
                if (index == item.Index)
                {
                    item.Selected = true;
                }
                else
                {
                    item.Selected = false;
                }
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            HideMenu = true;
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            HideMenu = false;
        }


    }
}
